package Interpreter;

public class InterpretPatternDemo {

    // terminalExpression   interpret   context contains data

    public static Expression getMaleExpression(){
        Expression terExpression1 = new TerminalExpression("Tom");
        Expression terExpression2 = new TerminalExpression("Jack");

        return new OrExpression(terExpression1, terExpression2);  // 规则: Tom Jack 都是男性. 用 Tom Jack 去测试的规则叫做: OrExpression
    }


    public static Expression getMarriedWomenExpression(){
        Expression rose = new TerminalExpression("Rose");
        Expression marry = new TerminalExpression("Marry");

        return new AndExpression(rose, marry);
    }

    public static void main(String[] args) {
        // 这是两个规则 一个or 一个and
        Expression isMale = getMaleExpression();
        Expression isMarriedWoman = getMarriedWomenExpression();

        System.out.println("John is male? " + isMale.interpret("Tom"));  // or : 存在一个 Tom or Jack就是 true
        System.out.println("Rose is married? " + isMarriedWoman.interpret("Rose"));  // and Rose marry 都存才才行

    }

}
